import instance from "./api_instance";

// 登录接口
export const loginApi = (account: string, passwordMd5: string) => {
  return instance.post("user/login", { account, passwordMd5 });
};
// 注册接口
export const registerApi = (name: string, passwordMd5: string, email: string) => {
  return instance.post("user/signin", { name, passwordMd5, email });
};
// 定时刷新token
export const getTokenIntervalApi = () => {
  return instance.post("user/getnewtoken", { requestToGetNewToken: true });
};
// 请求添加好友/群
export const addFriendsApi = (requestAccount: string, type: number, remark?: string, sendMessage?: string) => {
  return instance.get("userfriendgroup/startRequest", {
    params: {
      requestAccount,
      account: localStorage["account"],
      type,
      remark,
      sendMessage
    }
  });
};
// 获取好友/群聊请求
export const getMyAddMsgApi = () => {
  return instance.get("userfriendgroup/getRequestList");
};
// 获取好友基础信息接口
export const getUserInfoListApi = (accountList: string[], startTime: number = 0) => {
  return instance.post("user/getinfolist", { accountList, startTime });
};
// 获取群基础信息接口
export const getGroupInfoListApi = (groupAccountList: string[], startTime: number = 0) => {
  return instance.post("groupbaseinfo/getGroupBaseList", { groupAccountList, startTime });
};
// 创建群聊
export const createGroupApi = (name: string, avatar?: string) => {
  return instance.get("groupbaseinfo/createGroup", {
    params: {
      leader: localStorage["account"],
      name,
      avatar
    }
  });
};
// 同意请求
export const agreeRequestApi = (senderAccount: string, type: number, receiverAccount?: string, sessionID?: string) => {
  return instance.get("userfriendgroup/agreeRequest", {
    params: {
      agreer: localStorage["account"],
      senderAccount,
      type,
      receiverAccount,
      sessionID
    }
  });
};
// 拒绝请求
export const refuseRequestApi = (senderAccount: string, type: number, receiverAccount?: string, sessionID?: string) => {
  return instance.get("userfriendgroup/refuseRequest", {
    params: {
      agreer: localStorage["account"],
      senderAccount,
      type,
      receiverAccount,
      sessionID
    }
  });
};
